<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let num1 = [1, 2, 3]
      let num2 = [2, 5, 6]
      function getConcat(arr1, arr2) {
        let i = 0,
          j = 0
        let res = []
        while (i < arr1.length && j < arr2.length) {
          // 互相比较，把小的那项推到新数组
          if (arr1[i] < arr2[j]) {
            res.push(arr1[i])
            i++
          } else if(arr1[i] > arr2[j]) {
            res.push(arr2[j])
            j++
        } else {
          res.push(arr1[i])
          res.push(arr2[j])
          i++,j++
        }
      }
      // 数组长度不一致，一边已经加完了的情况
      if(i < arr1.length){
        return  res.concat(arr1.splice(i)) // 返回值是该索引后被删除的元素
      } else if(j < arr2.length){
        return  res.concat(arr2.splice(j))
      } else
        return res
    }
      console.log(getConcat(num1, num2));
    </script>
  </body>
</html>
